package com.example.micro.netty.server.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * CompletableFuture异常抛出测试
 *
 * @author Code Farmer
 * @create 2020/10/8 11:13 上午
 */
public class ExceptionDemo1 {


    public static int filter() {
        throw new RuntimeException("测试抛出的异常");
    }

    public static Future<Integer> test1() {
        CompletableFuture completableFuture = new CompletableFuture<>();
        new Thread(() -> {
            try {
                int result = filter();
                completableFuture.complete(result);
            } catch (Exception e) {
                completableFuture.completeExceptionally(e);
            }
        }).start();
        return completableFuture;
    }

    public static void main(String[] args) throws Exception {
        test1().get();
    }

}
